package gitee.derumin.lifeissohard.mixin;

import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerEntity.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
    public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
        super(world, profile);
    }

    @Inject(method = "canSprint" , at = @At("RETURN") , cancellable = true)
    private void modifyCanSprint(CallbackInfoReturnable<Boolean> cir){
        Boolean bl = this.hasVehicle() || (float)this.getHungerManager().getFoodLevel() > 2.0F || this.getAbilities().allowFlying;
        cir.setReturnValue(bl);
    }

     @Inject(method = "tick" , at = @At(value = "INVOKE" , target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;tick()V"))
    private void sendPlayerInputC2SPacket(CallbackInfo ci){
        ClientPlayNetworking.send(LishIdentifiers.Packets.C2SPackets.PLAYER_INPUT_PACKET, LishNetworkPackets.createPlayerMoveInputPacket(
                this.input.movementForward,
                this.input.movementSideways,
                this.input.pressingForward,
                this.input.pressingBack,
                this.input.pressingLeft,
                this.input.pressingRight,
                this.input.jumping,
                this.input.sneaking));
    }
}
